﻿Public Class StringToIconConverter
    Implements IValueConverter

    Sub New()

    End Sub
    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Dim key As String = TryCast(value, String)
        'If String.IsNullOrEmpty(key) Then Return Application.Current.TryFindResource("chart_pie")
        'Return Application.Current.TryFindResource(key)
        If String.IsNullOrEmpty(key) Then Return "pack://application:,,,/OMANE.Common.UI.Theme;component/Images/chart_pie.png"
        If key.StartsWith("pack") Then Return value
        Return "pack://application:,,,/OMANE.Common.UI.Theme;component/Images/" & key & ".png"

    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class

Public Class FormulaConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Throw New NotImplementedException()
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class

Public Class InvertConverter
    Implements IValueConverter

    Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
        Try
            Dim mul As Double
            Try
                mul = CDbl(parameter)
            Catch ex As Exception
                mul = 1
            End Try
            Return mul * CDbl(1 / CDbl(value))
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
        Throw New NotImplementedException()
    End Function
End Class